﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using StartEAS_API.Utils;
using StartsEAS_API.BLL.Interfaces.IProfessionalB;
using StartsEAS_API.Model;
using StartsEAS_API.Model.Models;

namespace StartsEAS_API.Controllers.ProfessionalContor
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [EnableCors("any")]
    public class ProfessionalController : ControllerBase
    {
        private readonly IProfessionalBLL _professionalBll;

        public ProfessionalController(IProfessionalBLL professionalBll) {
            _professionalBll = professionalBll;
        }
        /// <summary>
        /// 查询所有专业信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetAllProfessionals() {
            try
            {
                return _professionalBll.GetAllProfessionals();
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetAllProfessionals服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据id查询专业信息
        /// </summary>
        /// <param name="professionalId">专业id</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetProfessionalById(int professionalId) {
            try
            {
                return _professionalBll.GetProfessionalById(professionalId);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetProfessionalById服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 添加专业信息
        /// </summary>
        /// <param name="token">教务处token</param>
        /// <param name="professionalName">专业名称</param>
        /// <returns></returns>
        [HttpPost]
        public ResultUtils AddProfessional(string token, string professionalName, int CollegeId) {
            try
            {
                return _professionalBll.AddProfessional(token, professionalName, CollegeId);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"AddProfessional服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 修改专业信息
        /// </summary>
        /// <param name="token">教务处token</param>
        /// <param name="data">修改的专业信息</param>
        /// <returns></returns>
        [HttpPut]
        public ResultUtils UpdateProfessional(string token, Professional data) {
            try
            {
                return _professionalBll.UpdateProfessional(token, data);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"UpdateProfessional服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据学院编号查询专业列表
        /// </summary>
        /// <param name="CollegeId">学院编号</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetProfessionalsByCollegeId(int CollegeId)
        {
            try
            {
                return _professionalBll.GetProfessionalsByCollegeId(CollegeId);
            }
            catch (System.Exception e) {
                AppLog.WriteError($"GetProfessionalsByCollegeId服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }



    }
}
